SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tms_company_account_period
-- ----------------------------
DROP TABLE IF EXISTS `tms_company_account_period`;
CREATE TABLE `tms_company_account_period` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `company_id` bigint NOT NULL COMMENT '公司ID',
  `credit_limit` decimal(18,2) NOT NULL COMMENT '授信额度（元）',
  `credit_alert_amount` decimal(18,2) NOT NULL COMMENT '授信预警金额（元）',
  `current_credit_used` decimal(18,2) NOT NULL DEFAULT 0 COMMENT '当前合作金额（元）',
  `billing_cycle_days` int NOT NULL COMMENT '账期天数',
  `billing_alert_days` int NOT NULL COMMENT '账期提前提醒天数',
  `billing_start_date` date DEFAULT NULL COMMENT '账期开始日期',
  `billing_due_date` date DEFAULT NULL COMMENT '账期到期日期',
  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bigint NOT NULL DEFAULT 0 COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_company_id` (`company_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='公司账期信息';

-- ----------------------------
-- Records of tms_company_account_period
-- ----------------------------
BEGIN;
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;



-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '公司账期信息管理', '', 2, 0, 5042,
           'company-account-period', '', 'tms/period/index', 0, 'CompanyAccountPeriod'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();

-- 按钮 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '公司账期信息查询', 'tms:company-account-period:query', 3, 1, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '公司账期信息创建', 'tms:company-account-period:create', 3, 2, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '公司账期信息更新', 'tms:company-account-period:update', 3, 3, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '公司账期信息删除', 'tms:company-account-period:delete', 3, 4, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '公司账期信息导出', 'tms:company-account-period:export', 3, 5, @parentId,
           '', '', '', 0
       );
